home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 898 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: chewy.vcx.net!usenet
  2. From: Bruce Arnold <barnold@vcx.net>
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: Q: Time to call a function?
  5. Date: Mon, 08 Jan 1996 01:48:49 -0800
  6. Organization: Sprint United Telephone/Eastern - Internet @ccess
  7. Message-ID: <30F0E881.5F3D@vcx.net>
  8. References: <4cnjsf$kq0@mark.ucdavis.edu>
  9. NNTP-Posting-Host: y-wing-2a-4.tatooine.vcx.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b2a (Windows; I; 16bit)
  14.  
  15. > About how much time does calling a function, allocating memory, and
  16. > executing simple statements like "i = 3" take? 
  17.  
  18. The Intel programmers reference manual lists the number of clocks for 
  19. each instruction.  This varies from about 2 to 250.  The above 
  20. assignment statement probably uses a memory MOV which may take 20 clocks
  21. depending on the processor.  A 'CALL' to a subroutine can take over 200.
  22. Memory allocation might require many CALL's and other instructions
  23. amounting to perhaps 10,000 to 100,000 clocks.
  24.  
  25. To get back to 'time' (for the ballpark calculation) note that a 
  26. processor running at 66 MHZ has a clock time of 15 nanoseconds.
  27. ( 1 / 66,000,000 ).  That memory allocation which required 100,000
  28. clocks will take 1.5 milliseconds.  That assignment will take 
  29. 20 * 15ns = 300ns or 0.3 microsecs.  
  30.  
  31. It can be very tedious to try to calculate the exact value by looking
  32. at the assembly source code; that's what benchmarks are for.
  33. Note also that in real computers, most of the time is spent doing data
  34. input / output to storage devices and sending data to the screen.
  35.  
  36. Bruce.
  37.